import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import './assets/reset/index.css'
import './api/mock'
import api from './api/api'
import { SelectMenu } from "./stores/menu";
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.config.globalProperties.$api = api
app.use(createPinia())
const store = SelectMenu();
store.addMenu(router);
router.beforeEach((to,from,next)=>{
    store.getToken('token');
    const token = store.token;
    if(!token && to.name !=='login'){
       ElMessage('当前尚未登陆')
        next('/login')
    }else{
        next()
    }
})
app.use(router)

app.mount('#app')
